package com.java.basis.collection;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wangning
 * @date 2023/5/12 17:33
 */
public class MapNotSafeDemo {
    public static void main(String[] args) {
//        Map<String, String> map = new HashMap<>();
//        Map<String, String> map = new Hashtable<>();
//        Map<String, String> map = Collections.synchronizedMap(new HashMap<>());
        Map<String, String> map = new ConcurrentHashMap<>();

        for (int i = 1; i <= 30; i++) {
            new Thread(() -> {
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0, 8));
                System.out.println(map);
            }, String.valueOf(i)).start();
        }
        //java.util.ConcurrentModificationException
    }
}
